package com.mystnihon.freeremote.data;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;

import org.json.JSONObject;

import com.mystnihon.freeremote.db.table.ProgramTable;
import com.mystnihon.freeremote.util.Constants;

public class Program extends ProgramTable implements Serializable {

	/**
     * 
     */
	private static final long serialVersionUID = 8417407659440266200L;
	private static final String CHANNEL_ID = "channel_id";
	private static final String RESUME = "resume_l";
	private static final String DUREE = "duree";
	private static final String START = "datetime";
	private static final String END = "datetime_fin";
	private static final String GENRE = "genre_id";
	private static final String PROG_ID = "id";
	private static final String TITLE = "title";
	private static final String DESCRIPTION = "resum_s";

	private static SimpleDateFormat sdf = new SimpleDateFormat(Constants.WS_DATE_FORMAT, Locale.getDefault());

	public Program(JSONObject jobject) {

		mChannelId = jobject.optInt(CHANNEL_ID);
		mProgramId = jobject.optLong(PROG_ID);
		mTitle = jobject.optString(TITLE);
		mResume = jobject.optString(RESUME);
		mDescription = jobject.optString(DESCRIPTION);
		mGenre = jobject.optInt(GENRE);
		mDuration = jobject.optString(DUREE);

		try {
			mStartTime = sdf.parse(jobject.optString(START)).getTime();
			mEndTime = sdf.parse(jobject.optString(END)).getTime();
			
//			final long currenttime = System.currentTimeMillis();
//
//			if (mStartTime < currenttime && mEndTime > currenttime) {
//				System.out.println("Compris");
//			}
		} catch (ParseException e) {
			e.printStackTrace();
		}

	}
}
